﻿Public Class MainWindow

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        'Exit Program
        Me.Close()
    End Sub

    Private Sub AboutToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
        'Show About Box
        AboutBox1.ShowDialog()
    End Sub

    Private Sub RunToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RunToolStripMenuItem.Click
        'Check and see if the user is running without setting domains
        If QueryDomains Is Nothing Then
            MsgBox("You can not run a query on a blank domain list" & vbNewLine & "Go to options and specify Search Parameters before continuing")
            Exit Sub
        End If
        'Switch Cursor to Hour Glass
        Me.Cursor = Cursors.WaitCursor
        'Clear Results Pane
        ResultView.Rows.Clear()
        'Declare Variables
        Dim Domain As String
        Dim IPs
        Dim IP
        'Start For loop splitting the data by CR from QueryDomains global variable
        For Each Domain In QueryDomains.Split(vbNewLine)
            'Try statement to catch exceptions
            Try
                'Populate IPs as the LookupHost of the Domain trimmed to remove white space
                IPs = JHSoftware.DnsClient.LookupHost(Domain.Trim)
                'Write the IP's out to the Results Pane
                For Each IP In IPs
                    ResultView.Rows.Add(Domain.Trim, IP.ToString)
                Next

                'Error Handling
            Catch ex As JHSoftware.DnsClient.NXDomainException
                ResultView.Rows.Add(Domain.Trim, "Error: Domain Does Not Exist")

            Catch ex As JHSoftware.DnsClient.NoDataException
                ResultView.Rows.Add(Domain.Trim, "Error: Record Does Not Exist")

            Catch ex As JHSoftware.DnsClient.NoDefinitiveAnswerException
                ResultView.Rows.Add(Domain.Trim, "Error: No Definitive Answer")

            Catch ex As JHSoftware.DnsClient.NoDnsServersException
                ResultView.Rows.Add(Domain.Trim, "Error: No DNS Server Found to Process Request")

            Catch ex As Exception
                MsgBox("An exception has occured" & vbNewLine & "This can happen if you try to run a query with no domains specified")

            End Try

        Next
        'Switch Cursor Back to Arrow
        Me.Cursor = Cursors.Arrow

    End Sub

    Private Sub ClearToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
        'Clear Results Pane
        ResultView.Rows.Clear()
    End Sub

    Private Sub SearchParametersToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SearchParametersToolStripMenuItem.Click
        'Show Search Parameters Dialog Box
        SearchParams.ShowDialog()
    End Sub

    Private Sub MainWindow_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        QueryType = "A"
    End Sub

    Private Sub DNSServerToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DNSServerToolStripMenuItem.Click
        MsgBox("Feature Coming Soon")
    End Sub
End Class
